-
Couldn't load subscription status.
- Fork 487
Perf: Improve gkr-mimc memory use #1616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/gkr/hashes
Are you sure you want to change the base?
Conversation
This reverts commit c6b830c.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes memory usage in the GKR-MiMC implementation by introducing memory pooling for field element allocations and adding a specialized SumExp17 operation. The changes result in a 20% reduction in heap allocation (from 2267.45 MB to 1798.62 MB) for BLS12-377 benchmarks.
- Memory pool implementation in
gateAPIto reduce heap allocations - New
SumExp17method for optimized computation of (a+b+c)^17 operations - Refactoring from global to instance-based API usage patterns
Reviewed Changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| std/gkrapi/gkr/types.go | Adds SumExp17 method to GateAPI interface |
| std/gkrapi/compile.go | Wraps API with FrontendAPIWrapper for gate evaluation |
| internal/gkr/gkr.go | Adds FrontendAPIWrapper with SumExp17 implementation |
| std/permutation/gkr-mimc/gkr-mimc.go | Optimizes addPow17 function with BLS12-377 specific caching |
| Multiple internal/gkr/*/gkr.go | Implements memory pooling in gateAPI across all curve implementations |
| Multiple internal/gkr/*/solver_hints.go | Updates to use instance-based gateAPI |
| Test files | Renames hashTreeCircuit to merkleTreeCircuit and improves test configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Improves the amount of heap allocations in the benchmark of a 2^16 BLS12-377 element long hash down to 1798.62 MB on an hpc6a.48xlarge machine. This constitutes a 20% improvement over the linea-monorepo baseline (2267.45 MB.)
Most of the improvement was achieved by introducing a reusable pool / stack for temporary field element variables, and is generic to any use of the GKR API.
A further reduction was due to a hard-coded implementation of the most commonly used MiMC gate in BLS12-377, which is
(state + msg + key)^17.I believe that for small instance sizes (< 2^16) the cost is dominated by the GKR verifier and the PLONK prover itself. From that point on, the slope of the fitted line (<1) suggests an at most linear rate of growth.
Note
Introduce a pooled, pointer-based GateAPI (with SumExp17) and plumb it through GKR/MiMC paths to cut heap allocations; update engine hints, templates, SNARK wrapper, and tests/benchmarks.
gateAPIwith a synchronous memory pool (allocated,nbUsed), pointer receivers,newElement,freeElements, and methodcastrefactor.SumExp17inGateAPI; addFrontendAPIWrapper.SumExp17for in-circuit use; update interface instd/gkrapi/gkr/types.go.apiusage with localgateAPIinstances and pass by pointer in evaluation paths (computeGJ, degree checks, equality tests, hints,Complete).wire.Gate.Evaluateto useFrontendAPIWrapper.gateAPIto holdmod *big.Int; fix modular reductions.frontend.Variableper curve; register gates using new types.SumExp17path for degree-17 S-box; keep pow5/pow7 forms.gateAPIand pointer API.freeElements()calls in loops hot paths.Written by Cursor Bugbot for commit f6613ce. This will update automatically on new commits. Configure here.